package modifier;

import character.MyCharacter;

public abstract class TickingModifier {
    protected MyCharacter owner;
    //Note: Ticks can represent any length of time, it just depends on how often the modifier is ticked.
    protected int totalTicks, ticksRemaining;
    protected boolean markedForRemoval = false;

    @Deprecated
    protected TickingModifier() {}
    
    public TickingModifier(MyCharacter owner, int totalTicks) {
        this.owner = owner;
        this.totalTicks = totalTicks;
        ticksRemaining = totalTicks;
    }
    
    public void applyModifier() {
        apply();
    }

    public void tickModifier() {
        if(ticksRemaining == 0) {
            completeModifierNaturally();
        } else {
            tick();
            ticksRemaining--;
            if(ticksRemaining == 0)
                completeModifierNaturally();
        }
    }

    protected void completeModifierNaturally() {
	completeNaturally();
	markedForRemoval = true;
    }
    
    public void abortModifier() {
        abort();
	markedForRemoval = true;
    }

    protected abstract void apply();
    protected abstract void tick();
    protected abstract void completeNaturally();
    protected abstract void abort();

    public int getTotalTicks() {
        return totalTicks;
    }
    public void setTotalTicks(int totalTicks) {
        this.totalTicks = totalTicks;
        ticksRemaining = totalTicks;
    }
    public int getTicksRemaining() {
        return ticksRemaining;
    }
    public void setTicksRemaining(int ticksRemaining) {
        this.ticksRemaining = ticksRemaining;
    }

    public boolean isMarkedForRemoval() {
	return markedForRemoval;
    }
    
    public void cloneMe(TickingModifier tickingModifier) {
        tickingModifier.totalTicks = totalTicks;
        tickingModifier.ticksRemaining = ticksRemaining;
        tickingModifier.markedForRemoval = markedForRemoval;
    }

    @Override
    /** The default requirement for a TickingModifier's equals is just to be of the same class.
     * Override this if a subclass requires other stipulations.
     */
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        return hash;
    }
}
